//
//  ZCToolBarView.swift
//  weibo
//
//  Created by 张城 on 16/7/23.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit

class ZCToolBarView: UIView {
    
    var replyBut: UIButton?
    
    var commentBut: UIButton?
    
    var likeBut: UIButton?
    
    
    var homeCellViewModel: ZCHomeCellViewModel? {
        didSet{
            
            self.replyBut?.setTitle(homeCellViewModel?.repostsCountStr, forState: .Normal)
            self.commentBut?.setTitle(homeCellViewModel?.commentsCountStr, forState: .Normal)
            self.likeBut?.setTitle(homeCellViewModel?.attitudesCountStr, forState: .Normal)
            
            
            
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor.greenColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupUI(){
        replyBut = addButton("timeline_icon_retweet", title: "转发")
        commentBut = addButton("timeline_icon_comment", title: "评论")
        likeBut = addButton("timeline_icon_unlike", title: "赞")
        let line1 = setline()
        let line2 = setline()
        
        
        replyBut!.snp_makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
//            make.width.equalTo(commentBut)
        }
        
        line1.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(replyBut!.snp_trailing)
        }
        
        commentBut!.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.width.equalTo(replyBut!)
            make.leading.equalTo(replyBut!.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentBut!.snp_trailing)
        }
        
        likeBut!.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.width.equalTo(commentBut!)
            make.leading.equalTo(commentBut!.snp_trailing)
        }
        
        
//        areTheyEqual("rew", y: "rew")
    }
    
    func setline() -> UIImageView {
        let imgv = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imgv)
        return imgv
    }
    
    
    func addButton(imgName: String, title: String)->UIButton {
        let button = UIButton()
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setImage(UIImage(named:imgName), forState: .Normal)
        addSubview(button)
        return button
    }
//    func areTheyEqual<T : Equatable>(x : T, y : T) -> Bool {
//        return x == y
//    }
    
    
}
